package com.vincce.sport.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.vincce.sport.entity.PlayerDateByBackboard;
import com.vincce.sport.entity.PlayerDateByHit;
import com.vincce.sport.entity.PlayerDateByTotalScore;
import com.vincce.sport.mapper.DateViewMapper;

@Controller
@RequestMapping("/queryPlayerDateApi")
public class InterfaceController extends BaseController{
	@Resource
	private DateViewMapper dateViewMapper;
	/**
     * 个人篮板
     * @param model
     * @param user
     * @param request
     * @return
     * @throws IOException
     */
    @RequestMapping("/queryPlayerDateByBackboardApi")
    @ResponseBody
    public String queryPlayerDateByBackboardPage(Model model, Long seasonId,Long offset,Long limit, HttpServletRequest request, HttpServletResponse response){
    	int count=0;
    	String msg="";
    	List<PlayerDateByBackboard> dataList=null;
    	if(checkIp(request)){
    		if(limit==null || limit>20){
        		limit=20l;
        	}
    		if(offset==null){
    			offset=0l;
        	}
        	try{
        		Map<String, Object> map = new HashMap<String, Object>();    	
            	map.put("seasonId", seasonId);
            	map.put("offset", offset);
            	map.put("limit", limit);
            	dataList=dateViewMapper.queryPlayerDateByBackboardPage(map);
        		count=1;
        		msg="调用接口成功";
        	}catch(Exception ex){
        		ex.getMessage();
        		count=0;
        		msg="调用接口失败";
        	}   	
    	}else{
    		count=0;
    		msg="此IP地址无效";
    	}
    	
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("msg", msg);
        result.put("suc", count > 0 ? true : false);
        result.put("list", dataList);
        return JSON.toJSONString(result);
    }
    /**
     * 个人命中率
     * @param model
     * @param user
     * @param request
     * @return
     * @throws IOException
     */
    @RequestMapping("/queryPlayerDateByHitApi")
    @ResponseBody
    public String queryPlayerDateByHitPage(Model model, Long seasonId,Long offset,Long limit, HttpServletRequest request, HttpServletResponse response){
    	int count=0;
    	String msg="";
    	List<PlayerDateByHit> dataList=null;
    	if(checkIp(request)){
    		if(limit==null || limit>20){
        		limit=20l;
        	}
    		if(offset==null){
    			offset=0l;
        	}
        	try{
        		Map<String, Object> map = new HashMap<String, Object>();    	
            	map.put("seasonId", seasonId);
            	map.put("offset", offset);
            	map.put("limit", limit);
            	dataList=dateViewMapper.queryPlayerDateByHitPage(map);
        		count=1;
        		msg="调用接口成功";
        	}catch(Exception ex){
        		ex.getMessage();
        		count=0;
        		msg="调用接口失败";
        	}   	
    	}else{
    		count=0;
    		msg="此IP地址无效";
    	}
    	
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("msg", msg);
        result.put("suc", count > 0 ? true : false);
        result.put("list", dataList);
        return JSON.toJSONString(result);
    }
    /**
     * 	个人得分排行
     * @param model
     * @param user
     * @param request
     * @return
     * @throws IOException
     */
    @RequestMapping("/queryPlayerDateByTotalScoreApi")
    @ResponseBody
    public String queryPlayerDateByTotalScorePage(Model model, Long seasonId,Long offset,Long limit, HttpServletRequest request, HttpServletResponse response){
    	int count=0;
    	String msg="";
    	List<PlayerDateByTotalScore> dataList=null;
    	if(checkIp(request)){
    		if(limit==null || limit>20){
        		limit=20l;
        	}
    		if(offset==null){
    			offset=0l;
        	}
        	try{
        		Map<String, Object> map = new HashMap<String, Object>();    	
            	map.put("seasonId", seasonId);
            	map.put("offset", offset);
            	map.put("limit", limit);
            	dataList=dateViewMapper.queryPlayerDateByTotalScorePage(map);
        		count=1;
        		msg="调用接口成功";
        	}catch(Exception ex){
        		ex.getMessage();
        		count=0;
        		msg="调用接口失败";
        	}   	
    	}else{
    		count=0;
    		msg="此IP地址无效";
    	}
    	
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("msg", msg);
        result.put("suc", count > 0 ? true : false);
        result.put("list", dataList);
        return JSON.toJSONString(result);
    }
}
